package com.ysd.lis.util.qcrule;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

public class Test {
    static void   addResults( List<Result> results,String uuid,String no,int mean,int sd,Double numreslut){
        Result r = new Result();
        r.setId(uuid);
        r.setQCBatchNo(no);
        r.setMean(mean);
        r.setSd(sd);
        r.setNumResult(numreslut);
        r.setZvalue(sd==0?0:(numreslut - mean) / sd);
        results.add(r);
    }
    public static void main(String[] args) {
        QCResult qcData0 = new QCResult();

        List<Result> results = qcData0.getResults();
        addResults(results,UUID.randomUUID().toString(),"2022-01-01",0,1,-4.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-02",0,1,-3.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-03",0,1,-2.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-04",0,1,-1.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-05",0,1, 0.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-06",0,1,1.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-07",0,1,2.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-08",0,1,3.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-09",0,1,4.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-10",0,1,-2.1);
        addResults(results,UUID.randomUUID().toString(),"2022-01-10-2",0,1,2.1);

        QCResult qcData1 = new QCResult();
        List<Result> results1 = qcData1.getResults();
        addResults(results1,UUID.randomUUID().toString(),"2022-01-01",0,1,-4.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-02",0,1,-3.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-03",0,1,-2.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-04",0,1,-1.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-05",0,1, 0.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-06",0,1,1.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-07",0,1,2.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-08",0,1,3.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-09",0,1,4.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-10",0,1,1.2);
        addResults(results1,UUID.randomUUID().toString(),"2022-01-10-2",0,1,1.2);

        QCResult qcData2 = new QCResult();
        List<Result> results2 = qcData2.getResults();
        addResults(results2,UUID.randomUUID().toString(),"2022-01-01",0,1,-4.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-02",0,1,-3.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-03",0,1,-2.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-04",0,1,-1.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-05",0,1, 0.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-06",0,1,1.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-07",0,1,2.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-08",0,1,3.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-09",0,1,4.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-10",0,1,2.3);
        addResults(results2,UUID.randomUUID().toString(),"2022-01-10-2",0,1,3.3);


        List<QCResult> qcDatas = new ArrayList<>();
        qcDatas.add(qcData0);
        qcDatas.add(qcData1);
        qcDatas.add(qcData2);



        RuleManager ruleManager = new RuleManager();
        //ruleManager.Register(RuleType.AXRule, Guid.NewGuid(), "2x", 2, 2, 0);
        //ruleManager.Register(RuleType.ATRule, Guid.NewGuid(), "2t", 2, 2, 0);
        ruleManager.Register(RuleType.ALRule, UUID.randomUUID().toString(), "12s", 1, 1, 2);
        ruleManager.Register(RuleType.ALRule, "1111111111", "22s", 2, 2, 2);
        ruleManager.Register(RuleType.ALRule, "22222222222", "41s", 4, 4, 1);
        ruleManager.Register(RuleType.RLRule, "33333333333", "r4s", 2, 2, 4);
        //ruleManager.Register(RuleType.AOfNLRule, Guid.NewGuid(), "20f3-2s", 2, 3, 2);

        for (Rule r : ruleManager.getRules())
        {
            //Console.WriteLine(r.Name + "    " + r.Id);
            System.out.println(r.getName()+"  "+r.getId());
        }


        //DateTime beforDT = System.DateTime.Now;
        long beforDT = System.currentTimeMillis();


        List<RuleType> types = ruleManager.EvaluateMulti(qcDatas);

        //Rule rule;

        //rule = new ALRule(Guid.NewGuid(),"61s",6,6, 1);

        //var qcresult = rule.EvaluateMulti(ref qcDatas);

        //DateTime afterDT = System.DateTime.Now;
        long afterDT = System.currentTimeMillis();
        //TimeSpan ts = afterDT.Subtract(beforDT);
        long s = afterDT-beforDT;
        //Console.WriteLine("总共花费{0}ms.", ts.TotalMilliseconds);
        System.out.println("总共花费{0}ms."+s/1000);



        for (QCResult qcData : qcDatas)
        {
            System.out.println("QCMaterial ");


            for (Result item : qcData.getResults())
            {
                //Console.WriteLine(item.Id + "   " + item.QCBatchNo + "     " + item.Z.ToString());
                System.out.println(item.getId() + "   " + item.getQCBatchNo() + "     " + item.getZvalue());
                if (item.getIsOutControl())
                {
                    StringBuffer sb = new StringBuffer() ;
                    for(OutControlInfo o : item.getOutControlInfos())
                    {
                        //Console.WriteLine("OC:" + o.RuleId +"  "+ o.IsMutiMaterial + " Members:" + string.Join(",", o.MemberIds));
                        System.out.println("OC:" + o.getRuleId() +"  "+ o.getIsMutiMaterial() + " Members:" + o.getMemberIds());
                    }

                }


            }
        }

    };
}

